package com.tianji.learning.listeners;

import com.tianji.api.dto.trade.OrderBasicDTO;
import com.tianji.common.constants.MqConstants;
import com.tianji.common.utils.CollUtils;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.po.PointsRecord;
import com.tianji.learning.enums.PointsRecordType;
import com.tianji.learning.listeners.message.SignInMessage;
import com.tianji.learning.service.ILearningLessonService;
import com.tianji.learning.service.IPointsRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Component
public class LearningPointsChangeListener {
    private final IPointsRecordService recordService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "learning.sign.points.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.SIGN_IN
    ))
    public void addSignInRecord(SignInMessage message){
        //监听签到积分消息
        recordService.addPointsRecord(message,PointsRecordType.SIGN);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "learning.QA.points.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.WRITE_REPLY
    ))
    public void learningReplyPoints(SignInMessage message){
        //监听问答积分消息
        recordService.addPointsRecord(message,PointsRecordType.QA);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "learning.notes.points.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.WRITE_NOTE
    ))
    public void learningNotesPoints(SignInMessage message){
       //监听笔记积分消息
        recordService.addPointsRecord(message,PointsRecordType.NOTE);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "learning.section.points.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.LEARN_SECTION
    ))
    public void learningPoints(SignInMessage message){
        //监听学习课程小节积分消息
        recordService.addPointsRecord(message,PointsRecordType.LEARNING);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "learning.notesGathered.points.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.NOTE_GATHERED
    ))
    public void learningNoteGatheredPoints(SignInMessage message){
        //监听笔记被采纳积分消息
        recordService.addPointsRecord(message,PointsRecordType.NOTE);
    }
}
